<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="cn.edu.cxcyzx.entity.*,java.util.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>创新创业中心管理平台</title>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
  <link href="${pageContext.request.contextPath}/css/bootstrap.css" rel="stylesheet">
  <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
	<!-- bootstrap theme -->
   <link href="${pageContext.request.contextPath}/css/bootstrap-theme.css" rel="stylesheet">
</head>

  <!-- 模态框：修改密码 -->
<div class="modal fade" id="updatePwd_Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div  class="modal-dialog" role="document" style="margin-right: 900px">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">修改登陆密码</h4>
      </div>
      <div class="modal-body">
        <form>
		  <div class="form-group">
		    <label for="pwd">密码</label>
		    <input type="password" class="form-control" id="pwd" placeholder="密码必须为8-16位，同时包含数字和字母">
		  </div>
		  <div class="form-group">
		    <label for="re_pwd">确认密码</label>
		    <input type="password" class="form-control" id="re_pwd" placeholder="再次输入相同密码">
		  </div>
		</form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="save_btn">保存</button>
      </div>
    </div>
  </div>
</div>

<!-- 模态框：重新登陆 -->
<div aria-hidden="true" data-backdrop="static" class="modal fade" id="relogin_Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div  class="modal-dialog" role="document" style="margin-right: 1500px;margin-top: 100px">
    <div class="modal-content">
      <div class="modal-body">
        <form class="form-horizontal">
		  <div class="form-group">
		  	<label class="col-sm-2 control-label">
		  		<i class="layui-icon" style="font-size: 30px; color: #00BFFF;">&#xe605;</i>
		  		
		  	</label>
		    <div class="col-sm-5" style="margin-top: 10px">
		    	<p style="margin-top: 5px">密码修改成功</p>
		    </div>	 
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label" for="downTime">
		    	<i class="layui-icon" style="font-size: 30px; color: #FF0000;">&#xe63d;</i>
		    </label>
		    <div class="col-sm-5">
		    	<input type="text" id="downTime" value="xx秒后将转到登陆页面" class="form-control" readonly="readonly">
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label">
		    	<i class="layui-icon" style="font-size: 30px; color: #FFC0CB;">&#xe609;</i>
		    </label>
		    <div class="col-sm-2" style="margin-top: 15px">
		    <p>
		    	<a href="javascrip:void(0);" onclick="relogin()">登陆
		    	</a>
		    </p>
		    </div>
		  </div>
		</form>
      </div>
    </div>
  </div>
</div>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">
	  <div class="layui-header">
	    <div class="layui-logo">创新创业中心管理平台</div>
	    <!-- 头部区域（可配合layui已有的水平导航） -->
	    
	    <ul class="layui-nav layui-layout-right">
	      <li class="layui-nav-item">
	        <a href="javascript:;">管理员</a>
	        <dl class="layui-nav-child">
	          <dd><a href="javascrip:void(0)">个人中心</a></dd>
	          <dd><a href="javascrip:void(0);" onclick="update_pwd()">修改登陆密码</a></dd>
	        </dl>
	      </li>
	      <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/admin_stu/quit.do">退出</a></li>
	    </ul>
	  </div>
	  
	  <div class="layui-side layui-bg-black">
	    <div class="layui-side-scroll">
	      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
	      <ul class="layui-nav layui-nav-tree"  lay-filter="test">
	      	<li class="layui-nav-item">
	      		<a href="${pageContext.request.contextPath}/admin_stu/home.do">房间管理</a>
	      	</li>
	        
	      </ul>
	    </div>
	  </div>
  
  <div class="layui-body" >
    <!-- 内容主体区域 
    <div style="padding: 15px;">内容主体区域</div>
    -->
  </div>
</div>
		<script src="${pageContext.request.contextPath}/js/jquery.js"></script>
		<script src="${pageContext.request.contextPath}/js/jquery-ui-1.10.4.min.js"></script>
	    <script src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
	    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.min.js"></script>
	    <!-- bootstrap -->
	    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
		<script src="${pageContext.request.contextPath}/layer/layer.js"></script>
		<script src="${pageContext.request.contextPath}/layui/layui.js" charset="UTF-8"></script>
<script>
	//JavaScript代码区域
	layui.use('element', function(){
	  var element = layui.element;
	  
	});
	//修改登陆密码
	function update_pwd(){
		$('#updatePwd_Modal').modal('toggle');
	}
	$("#pwd").blur(function(){
		var pwd=$("#pwd").val();
		console.log("pwd:"+pwd);
		var pwdReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/;//8到16位数字与字母组合
		 if(!pwdReg.test(pwd)){
			 $("#pwd").val("");
			 layer.msg('密码格式错误', {icon: 2,anim:6,time:1000});
			 
         }
	});
	$("#re_pwd").blur(function(){
		var re_pwd=$("#re_pwd").val();
		var pwd=$("#pwd").val();
		console.log("re_pwd:"+re_pwd);
		if(pwd!=""&&re_pwd==pwd){
			layer.msg('密码格式正确', {icon: 1});
		}else{
			$("#re_pwd").val("");
			layer.msg('两次密码不一致', {icon: 2,anim:6,time:1000});
		}
	});
	$("#save_btn").click(function(){
		var re_pwd=$("#re_pwd").val();
		var pwd=$("#pwd").val();
		if(pwd!=""&&re_pwd!=""&&re_pwd==pwd){
			console.log("ok");
			$('#updatePwd_Modal').modal('toggle');
			$.get("${pageContext.request.contextPath}/update_pwd.do?pwd="+pwd)
				.done(function(result){
					if(result.code==100){
						$('#relogin_Modal').modal('toggle');
						var obj=$("#downTime");
						setTime(obj);
					}else{
						layer.msg('密码修改失败', {icon: 2});
					}
				});
			
		}else{
			layer.msg('请先正确输入密码', {icon: 2});
		}
	});
	var countdown=10; 
	function setTime(obj){
		console.log(countdown);
		if(countdown==-1){
			countdown = 60;
			relogin();
	        return;
		}else{
			obj.val(countdown+"秒后将转到登陆页面");
			countdown--;
		}
		//阻塞一秒
		setTimeout(function(){
			setTime(obj)}
			,1000)
		
	}
	//重新登陆
	function relogin(){
		$.ajax({
			type:"GET",
			url:"${pageContext.request.contextPath}/admin_stu/relogin.do",
			success:function(){
				window.location.href="${pageContext.request.contextPath}/"
			}
		});
	}
</script>
</body>
</html>